import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image, Picker, Swiper, SwiperItem } from '@tarojs/components'
import { AtForm, AtInput } from 'taro-ui'
import './createLabel.scss'
import { $redirectTo } from '../../../global';
import reactMixin from 'react-mixin';
import myJs from './createLabelJs.js'
import app from '../../../main.js'

export default class CreateLabel extends Component {
    config = {
        navigationBarTitleText: '新建标签'
    }
    constructor() {
        super(...arguments);
        this.state = this.getData();
    }
    init() {
        this.setState({
            label_name:this.state.label_name,
        })
     }
     updateLabel() {
        var me = this;
        var data = me.state.label;
        var flag = true;
        if(me.beforeUpdateLabel) {
            flag = me.beforeUpdateLabel(data);
        }
        if(flag) {
            app.post("web/patientlabel/save", data, function(res) {
              me.navigateTo('../labelManage2/labelManage2')
            });
        }
    }
    beforeUpdateLabel(data){
        let ids='';
        data.label_name=this.state.label_name;
        this.state.label_id!=='0'?data.id=this.state.label_id:'';
        console.log(data);
        return true;
      }
    // save=()=>{
    //     app.redirectTo('../patientchoose/patientchoose');
    // }
    render() {
        return (
            <View className='createLabel'>
                <AtForm>
                    <AtInput
                        name='value'
                        type='text'
                        placeholder='请输入标签'
                        value={this.state.label_name}
                        onChange={this.handleChange.bind(this,'label_name')}
                    />
                </AtForm>
                <View className=' class_0' onClick={this.updateLabel.bind(this)}>
                    <Text className=' class_1'>保存</Text>
                </View>
            </View>
        );
    }
}
reactMixin.onClass(CreateLabel, myJs);